package com.supermap.pisaclient.common;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.AlphaAnimation;
import android.widget.ImageView;

import com.supermap.pisaclient.R;

/**
 * Copyright (C) 2017 北京超图软件股份有限公司 版权所有
 * <p>
 * 功能描述：闪屏页 作者：李会林
 * <p>
 * 修改人： 修改描述： 修改日期
 */
public class SplashActivity extends Activity {
    private ImageView mSplashImageView;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_splash_screen);
        initView();
    }

    private void initView() {
        //检查是否有更新的操作
        //拉取接口 获取闪屏页的图片
        //接口拉取失败 就读取默认的图片
        mSplashImageView = (ImageView) findViewById(R.id.flash_img);
        checkUpdate();
        gotoStep();
    }

    private void checkUpdate() {

    }

    private void gotoStep() {
        AlphaAnimation animation = new AlphaAnimation(0, 1);
        animation.setDuration(800);
        animation.setFillAfter(true);
        mSplashImageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
            }
        });
        mSplashImageView.setBackgroundDrawable(null);
        mSplashImageView.setImageResource(R.drawable.start);
        mSplashImageView.startAnimation(animation);
        mSplashImageView.setVisibility(View.VISIBLE);
        new Handler().postDelayed(new Runnable() {

            @Override
            public void run() {
                //判断一下是否登陆
                Intent intent = new Intent(SplashActivity.this, MainActivity.class);
                startActivity(intent);
                finish();
            }
        }, 4000);
    }
}
